package com.evildog.workspace.life.application.controller;

import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.life.application.bo.NoteTagBO;
import com.evildog.workspace.life.application.convert.NoteTagConvert;
import com.evildog.workspace.life.application.model.NoteTagParam;
import com.evildog.workspace.life.application.service.NoteTagService;
import com.evildog.workspace.life.application.vo.NoteTagVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * noteTag Controller
    笔记标签
 * </p>
 *
 * @author evildog
 * @since 2020-08-04
 */
@RestController
@RequestMapping("/note-tags")
@AllArgsConstructor
@Api(tags = "noteTag相关接口")
public class NoteTagController {

    private NoteTagService noteTagService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<NoteTagVO> save(@RequestBody NoteTagParam noteTagParam) {
        NoteTagBO noteTagBO = noteTagService.save(NoteTagConvert.INSTANCE.convert(noteTagParam));
        return ResultGenerator.success(NoteTagConvert.INSTANCE.convert(noteTagBO));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(noteTagService.removeById(id));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody NoteTagParam noteTagParam) {
        return ResultGenerator.status(noteTagService.updateById(id, NoteTagConvert.INSTANCE.convert(noteTagParam)));
    }

}